//
//
//  护士操作考核 功能
//

#import "HNurseAssessViewController.h"
#import "HNurseAssessRecordViewController.h"
#import "HNurseAssessDetailEditViewController.h"
@interface HNurseAssessViewController ()

@property (nonatomic,strong)UITableView *theTableView;

@property (nonatomic,strong)NSMutableArray *theStandardArray;
@property (nonatomic,strong)NSMutableDictionary *theDataSource;

@property (nonatomic,strong)NSDictionary *theDictMenuParam;

@end

@implementation HNurseAssessViewController

-(instancetype)initWithMenuParam:(NSDictionary*) dictMenuParam{
    
    NSString *typeid = [dictMenuParam objectForKey:@"TYPE_ID"];
    
    TableQcStandard *standard = [[TableQcStandard alloc]init];
    self.theDataSource = [NSMutableDictionary new];
    
    self.theStandardArray = [standard GetQcStandardWithType_id:typeid];
    
    for (HQc_standardModel *m in self.theStandardArray) {
        NSArray *arr = [standard GetQcCodeWithParentId:m.STANDARD_ID parent_id:@"*"];
        [self.theDataSource setObject:arr forKey:m.STANDARD_ID];
    }
    
    self.theDictMenuParam = dictMenuParam;
    
    
    return self;
}

- (void)viewDidLoad {
    
    UIBarButtonItem *record = [[UIBarButtonItem alloc] initWithTitle:@"记录" style:UIBarButtonItemStylePlain target:self action:@selector(didRecordButttonClicked:)];
    self.navigationItem.rightBarButtonItem = record;

    
    [self.view addSubview:self.theTableView];
    [super viewDidLoad];
}

-(IBAction)didRecordButttonClicked:(id)sender{

    HNurseAssessRecordViewController *vc = [[HNurseAssessRecordViewController alloc]initWithMenuParam:self.theDictMenuParam];
    vc.title = @"历史记录";
    vc.type = @"guochengkaohe";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}




- (UITableView *)theTableView
{
    if (!_theTableView) {
        _theTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth , ScreenHeight - NavBarHeight) style: UITableViewStylePlain];
        _theTableView.dataSource = self;
        _theTableView.delegate = self;
        _theTableView.tableFooterView = [[UIView alloc]init];
        [_theTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _theTableView;
}


#pragma mark  委托  UITableView

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.theDataSource.allKeys.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    HQc_standardModel *model = self.theStandardArray[section];
    NSArray *arr = self.theDataSource[model.STANDARD_ID];
    return arr.count;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    HQc_standardModel *model = self.theStandardArray[section];
    return model.STANDARD_NAME;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"cell";
    UITableViewCell *cell = [self.theTableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    
    HQc_standardModel *stand = self.theStandardArray[indexPath.section];
    NSArray *arr = self.theDataSource[stand.STANDARD_ID];
    HQc_codeModel *model = arr[indexPath.row];
    cell.textLabel.text = model.CODE_NAME;
    cell.indentationWidth = 30;
    cell.indentationLevel = 1;
    cell.detailTextLabel.text = model.CODE_ID;
    //cell.accessoryType = UITableViewCellAccessoryDetailButton;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HQc_standardModel *stand = self.theStandardArray[indexPath.section];
    NSArray *arr = self.theDataSource[stand.STANDARD_ID];
    HQc_codeModel *model = arr[indexPath.row];
    
    HNurseAssessDetailViewController *vc = [[HNurseAssessDetailViewController alloc]initWithRootCode:model];
    //HNurseAssessFormController *vc = [[HNurseAssessFormController alloc]initWithStandard:model];
    //HNurseAssessForm2Controller *vc = [[HNurseAssessForm2Controller alloc]initWithStandard:model];
    
    vc.title = @"操作过程考核";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


@end
